package com.smart.campus.web.core.config;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
    
    @Override  
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler) throws Exception {
          
        Object user = request.getSession().getAttribute("loginStudent");
        log.info("学生端登录验证,当前登录学生信息：{}", JSON.toJSONString(user));
        if (user == null || user.equals(""))  {
            response.sendRedirect("/student/login");
            return false;  
        }
        return true;
    }  
}
